home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-08-16 | 1.6 KB | 83 lines | [TEXT/MPS ] |
- /*
- A5World.cp
-
- Implementation of A5 world maintenance class.
-
- This class maintains an A5 global space.
-
- by Patrick Beard.
-
- based on TN 256.
-
- ©1990 by Patrick C. Beard. All rights reserved.
- */
-
- #ifndef __A5WORLD__
- #include "A5World.h"
- #endif
-
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
-
- extern "C" {
- void A5Init(Ptr); // function that sets up (initializes) the A5 world.
- long A5Size(void); // function that returns the size of our A5 world.
- void init_vtbls(void); // function that initializes virtual tables.
- }
-
- // utility routine to switch A5's. (lifted from OSUtils.h)
- pascal Ptr SwapA5(Ptr newA5)
- = {0x2F4D,0x0004,0x2A5F};
-
- // constructor: set up the current App's required A5 world.
-
- A5World::A5World()
- {
- error = noErr; // default is no error.
- oldA5 = nil; // none established for them.
- worldSize = A5Size(); // store our size for speed.
- ourA5 = NewPtr(worldSize); // better not fail.
- if(!ourA5) {
- error = -1;
- return;
- }
-
- // initialize our globals.
- A5Init(ourA5 + worldSize - 32); // see TN 256.
-
- // call InitGraf to initialize quickdraw globals.
- GrafPtr aPort;
- GetPort(&aPort);
- Enter(); // go inside our world.
- InitGraf(&qd.thePort);
- SetPort(aPort);
-
- Leave(); // leave the virtual world.
- }
-
- A5World::~A5World()
- {
- Leave(); // restore any saved A5.
- if(ourA5)
- DisposPtr(ourA5);
- }
-
- void A5World::Enter()
- {
- GrafPtr currPort;
- GetPort(&currPort);
-
- oldA5 = SwapA5(ourA5 + (worldSize - 32));
-
- SetPort(currPort);
- }
-
- void A5World::Leave()
- {
- if(oldA5) {
- SwapA5(oldA5);
- oldA5 = nil; // clear it so we won't do it again.
- }
- }
-